package rank1300;

/**
 * 2660. 保龄球游戏的获胜者
 */
public class No2660 {
    public int isWinner(int[] player1, int[] player2) {
        int multi1 = 1, multi2 = 1, surplus1 = -1, surplus2 = -1, score1 = 0, score2 = 0;
        score1 = getScore(player1, multi1, surplus1, score1);
        score2 = getScore(player2, multi2, surplus2, score2);
        if (score1 == score2) return 0;
        return score1 - score2 > 0 ? 1 : 2;
    }

    private int getScore(int[] player, int multi, int surplus, int score) {
        for (int i : player) {
            if (surplus == 0) multi = 1;
            surplus--;
            score += multi * i;
            if (i == 10) {
                multi = 2;
                surplus = 2;
            }
        }
        return score;
    }
}
